<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Testimonial extends CI_Controller {

	function __construct()
	{
		parent::__construct();
		$this->load->helper('bantuan_helper');
		$this->load->helper('text');
		if(!$this->session->userdata('user_id') && !$this->session->userdata('user_display_name') ):
			redirect('backend');
		endif;
	}

	function index()
	{
		if(!$this->session->userdata('filter_testimonial')):
			$this->session->set_userdata('filter_testimonial','all');
		endif;
		$this->load->library('pagination');
		$offset = $this->uri->segment(4);
		$config['base_url'] = site_url().'/backend/testimonial/index';
		$config['per_page'] = $this->config->item('per_page');
		$config['uri_segment'] = '4';
		if($this->session->userdata('filter_testimonial')=='all'):
			$config['total_rows'] = count($this->get_data('all'));
			$data['res'] = $this->get_data('all',FALSE,$config['per_page'],$offset);
		else:
			$config['total_rows'] = count($this->get_data($this->session->userdata('filter_testimonial')));
			$data['res'] = $this->get_data($this->session->userdata('filter_testimonial'),FALSE,$config['per_page'],$offset);
		endif;
		$data['urut'] = $this->uri->segment(4);
		$data['title'] = 'Testimonial';
		$data['template'] = 'testimonial/index';
		$this->pagination->initialize($config);
		$this->load->view('backend/index',$data);
	}

	function view()
	{
		$id = $this->uri->segment(4);
		if(!empty($id)):
			if($_POST):
				$proses = $_POST['status'];
				$testi_id = $_POST['testi_id'];
				if($proses=='enable'):
					$data = array('status'=>'enable');
					$this->db->where('testi_id', $testi_id)->update('tb_testimonial',$data);
				elseif($proses=='disable'):
					$data = array('status'=>'disable');
					$this->db->where('testi_id', $testi_id)->update('tb_testimonial',$data);
				elseif($proses=='delete'):
					$this->db->where('testi_id', $testi_id)->delete('tb_testimonial');
				endif;
				redirect('backend/testimonial');
			else:
				$data['content'] = $this->get_data('all',$id);
				$data['title'] = 'Detail Testimonial';
				$data['template'] = 'testimonial/view';
				$this->load->view('backend/index',$data);
			endif;
		else:
			redirect('backend/testimonial','refresh');
		endif;
	}
	function delete()
	{
		$id = $this->uri->segment(4);
		if(!empty($id)):
			$this->db->where('testi_id',$id)->delete('tb_testimonial');
		endif;
		redirect('backend/testimonial','refresh');
	}
	
	function get_data($param, $testi_id=FALSE, $limit=FALSE, $offset=FALSE)
	{
		if($limit):
			$this->db->limit($limit,$offset);
		endif;
		
		if($param!='all'):
			if($param=='enable'):
				$this->db->where('status','enable');
			elseif($param=='disable'):
				$this->db->where('status','disable');
			endif;
		endif;
		$this->db->order_by('testi_id','desc');
		if($testi_id):
			$this->db->where('testi_id',$testi_id);
			return $this->db->get('tb_testimonial')->row();
		else:
			return $this->db->get('tb_testimonial')->result();
		endif;
	}
	
	function ajax_bulk_action($param)
	{
		foreach($_POST["testi_id"] as $testi_id):
			if($param=='enable'):
				$data = array('status'=>'enable');
				$this->db->where('testi_id',$testi_id)->update('tb_testimonial',$data);
			elseif($param=='disable'):
				$data = array('status'=>'disable');
				$this->db->where('testi_id',$testi_id)->update('tb_testimonial',$data);
			elseif($param=='delete'):
				$this->db->where('testi_id',$testi_id)->delete('tb_testimonial');
			endif;
		endforeach;
	}
	
	function filter_testimonial($status)
	{
		if($status):
			$this->session->set_userdata('filter_testimonial',$status);
			redirect('backend/testimonial');
		else:
			redirect('backend/testimonial','refresh');
		endif;
	}
}

/* End of file product_cat.php */
/* Location: ./system/application/controllers/backend/product_cat.php */
